<?php

namespace app\index\service;

use app\common\model\Consulting;
use app\index\dao\ConsultingMessageDao;
use app\index\model\UM as UM;
use ShidianUtil\Utils\TimeUtil;

/**
 * Class MessageReadService
 * @package app\index\service
 */
class MessageReadService
{
    // dao
    private ConsultingMessageDao $consultingMessageDao;

    public function __construct(ConsultingMessageDao $consultingMessageDao)
    {
        $this->consultingMessageDao = $consultingMessageDao;
    }

    /**
     * 更新
     * @param UM $user
     * @param int $id
     * @param array $params
     * @return void
     */
    public function modify(UM $user, $id, array $params): void
    {
        if (!is_id($id)) {
            return;
        }

        $memberId = $user->id;

        $consulting = Consulting::where('id', $id)->find();

        if (!$consulting) {
            return;
        }

        if ($consulting->memberId == $memberId) {
            $consulting->memberLastTime = TimeUtil::millitime();
            $consulting->save();
        }

        if ($consulting->lawyerId == $memberId) {
            $consulting->lawyerLastTime = TimeUtil::millitime();
            $consulting->save();
        }
    }

}
